var iNum1;
var iNum2;
var items = ['国际级','国家级','省级','市级','校级','院级','系级','与教师合作','参与学校科研项目研究开发'];
var levels =[["特等奖","一等奖","二等奖","三等奖","优秀奖","参与者"],["特等奖","一等奖","二等奖","三等奖","优秀奖","参与者","发表论文","投稿被录用","立项"],["特等奖","一等奖","二等奖","三等奖","优秀奖","参与者","发表论文","投稿被录用","立项"],["特等奖","一等奖","二等奖","三等奖","优秀奖","参与者","发表论文","投稿被录用","立项"],["特等奖","一等奖","二等奖","三等奖","优秀奖","参与者","发表论文","投稿被录用"],["特等奖","一等奖","二等奖","三等奖","优秀奖","参与者","发表论文","投稿被录用","立项"],["特等奖","一等奖","二等奖","三等奖","优秀奖","参与者"],["参与课题","发表论文"],["1个","2个","1个(做负责人)","2个(做负责人)","1个+1个(做负责人)"]
];
var points =[[[40],[35],[25],[20],[15],[7.5]],[[35],[30],[20],[15],[10],[5],[30],[8],[15]],[[25],[20],[15],[12],[9],[4.5],[20],[6],[10]],[[20],[15],[12],[10],[8],[4],[15],[4],5],[[17],[12],[10],[8],[6],[3],[10],[2]],[[15],[10],[8],[6],[4],[2],[8],[1],[3]],[[11],[6],[4],[3],[1.5],[0.75]],[[3],[3]],[[3],[6],[5],[10],[8]]];

$(document).ready(
    initdate()
);
function initdate(){

    $(function (){
        // // 1.页面加载初始化就已经填入默认值
        // for(var i=0;i<items.length;i++){
        //     $('.selItems').append('<option>'+items[i]+'</option>');
        // }
        // iNum1 = $(".selItems option:selected").index();
        // var default_uni = levels[iNum1];
        // for(var s=0;s<default_uni.length;s++){
        //     $('.selLevels').append('<option>'+default_uni[s]+'</option>');
        // }
        // iNum2 = $(".selLevels option:selected").index();
        // var default_mem = points[iNum1][iNum2];
        // for(var g=0;g<default_mem.length;g++){
        //     $('.selPoints').append('<option>'+default_mem[g]+'</option>');
        // }

        // 两个两个之间的绑定事件
        $(document).delegate('.selItems',"change",function () {

            $(this).parent('.form-group').children('.selLevels').children().remove();
            $(this).parent('.form-group').children('.selLevels').children('.selPoints').children().remove();
            iNum1 = $(this).children('option:selected').index();
            var alevels = levels[iNum1];
            for(var j=0;j<alevels.length;j++){
                $(this).parent('.mb-3').children('.selLevels').append('<option>'+alevels[j]+'</option>');
            }
            // $(this).next('select.selLevels').trigger("change");//三个联动的关键代码
            $(this).next().next('select.selLevels').trigger("change");//三个联动的关键代码
        });

        $(document).delegate('.selLevels',"change",function () {
            // $(this).next('select.selPoints').children().remove();
            $(this).next().next('select.selPoints').children().remove();
            iNum2 = $(this).children('option:selected').index();
            var apoints = points[iNum1][iNum2];
            for(var k=0;k<apoints.length;k++){
                // $(this).next('select.selPoints').append('<option>'+apoints[k]+'</option>');
                $(this).next().next('select.selPoints').append('<option>'+apoints[k]+'</option>');

            }
            addpoint();

        })
    })
}
function addpoint() {
    var countPoint=0;
    // if (itemID.id=="2"){
    //     // countPoint=2;
    // }
    $("select.selPoints").each(function (it) {

        countPoint=countPoint+Number($(this).children().text());
        // alert(countPoint)
    })

    $("#subtotal").val(countPoint);
    $("#score").val((countPoint*0.25).toFixed(2));
}
function add_bind_op(){
    // var iNum1;
    // var iNum2;
    // var items= ['高校计算机等级考试','全国计算机等级考试','软考(专业技能考试)','英语','驾驶证','初级会计证','教师资格证','红十字救护证'];
    // var levels =[["一级","二级","三级","四级"],["一级","二级","三级","四级"],["初级","中级","高级"],['四级','六级'],[""],[""],[""],[""]
    // ];
    // var points=[[[2],[4],[6],[8]],[[3],[5],[10],[15]],[[10],[15],[20]],[[10],[15]],[[5]],[[5]],[[10]],[[3]]];
    $(function(){
        // 1.页面加载初始化就已经填入默认值
        for(var i=0;i<items.length;i++){
            $('.selItems').last().append('<option>'+items[i]+'</option>');
        }
        iNum1 = $(".selItems option:selected").index();
        var default_uni = levels[iNum1];
        for(var s=0;s<default_uni.length;s++){
            $('.selLevels').last().append('<option>'+default_uni[s]+'</option>');
        }
        iNum2 = $(".selLevels option:selected").index();
        var default_mem = points[iNum1][iNum2];
        for(var g=0;g<default_mem.length;g++){
            $('.selPoints').last().append('<option>'+default_mem[g]+'</option>');
        }
        // 两个两个之间的绑定事件
    })

}